#include "dds_api.h"
#include "dds_common.h"
#include <string>
#include <iostream>
#include <thread>

using namespace minieye::DDS;

// 写线程，负责写入数据到客户端
void ThreadWriter(Writer* writer)
{
	for(int i = 0; i < 10; i++)
	{
		// 生成需要向客户端发送的消息
		std::string payload = "Hello world " + std::to_string(i);

		// 向queue写入数据
		int ret = writer->Write(payload.c_str(), payload.size());
		if(ret != DDSSuccess)
		{
			printf("Write failed, ret = %d\n", ret);
		}

		std::cout << "Write data = " << payload << std::endl;

		if(i != 4)
			std::this_thread::sleep_for(std::chrono::milliseconds(1000));
		else
			std::this_thread::sleep_for(std::chrono::milliseconds(3000));

	}
}

int main() {
  // 配置文件的路径
  const std::string configPath = "/home/mini/code/linux_hjh/minieye_dds/config.json";

  // 通过配置文件实例化一个Context对象
  Context ctx(configPath);

  // 通过Context对象实例化一个Writer对象
  // 第二个参数表示这个writer对象负责向话题test写入消息
  Writer writer(&ctx, "test");

  std::this_thread::sleep_for(std::chrono::seconds(4));

  ThreadWriter(&writer);

  while(1){}
  return 0;
}
